-- CALC_TENT_100_TARGET_CLASS

-- 计算帐篷的中心格子类型
return function()
    local marmite      = { ["class"] = 47, ["ratio"] = 15 };   -- 砂锅
    local storage_box  = { ["class"] = 48, ["ratio"] = 30 };   -- 储物箱
    local gamble       = { ["class"] = 49, ["ratio"] = 20 };   -- 赌桌
    local tied_pig     = { ["class"] = 67, ["ratio"] = 20 };   -- 被绑的野猪
    local blacksmith   = { ["class"] = 101, ["ratio"] = 10 };  -- 老旧的铁砧
    local crystal_ball = { ["class"] = 197, ["ratio"] = 5 };   -- 木桌（水晶球）
    local robber_diary = { ["class"] = 226, ["ratio"] = 5 };   -- 强盗的日记
    local fairy_cages  = { ["class"] = 228, ["ratio"] = 5 };   -- 妖精的铁笼
    local third_hand   = { ["class"] = 259, ["ratio"] = 20};   -- 木桌（第三只手升级）


    local arr = { marmite, storage_box, gamble, tied_pig,
        blacksmith, crystal_ball, robber_diary, fairy_cages, third_hand};

    local dungeonId = DungeonM.getDungeonId();
    local currentLayer = DungeonM.currentLayer();

    if table.indexOf({2, 23, 22}, dungeonId) > 0 and currentLayer == 1 then
        -- 第一层必定出现储物箱
        return 48;
    end

    -- 只在无尽中出现
    if dungeonId ~= 2 then
        robber_diary["ratio"] = 0;
        fairy_cages["ratio"] = 0;
        third_hand["ratio"] = 0;
    end

    local thirdHandClassId = 8163;

    -- 如果玩家身上没有第三只手或者不能升级了
    -- 不出现相关木桌
    if (ItemM.getAmount(ME.user, thirdHandClassId) <= 0 and not EquipM.isEquiped(thirdHandClassId))
        or not EquipM.canUpgradeSpecialEquip(thirdHandClassId) then
        third_hand["ratio"] = 0;
    end

    -- 铁砧15层开始出现
    local layer = DungeonM.currentLayer();
    if layer < 15 then
        blacksmith["ratio"] = 0;
    end

    if TiedPigM.hasTiedPig() then
        -- 已经解救过野猪了，将权重置为0
        tied_pig["ratio"] = 0;
    end

    -- 先过滤一遍
    DungeonInstanceM.filterInstanceGrids(arr);

    local seed = DungeonM.getRandSeed("CALC_TENT_TARGET_CLASS");
    local info = fetchElemBySeed(arr, seed);

    return info["class"];
end
